1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module soup.MessageBody; 26 27 private import glib.ConstructionException; 28 private import glib.MemorySlice; 29 private import glib.Str; 30 private import glib.c.functions; 31 private import gobject.ObjectG; 32 private import linker.Loader; 33 private import soup.Buffer; 34 private import soup.c.functions; 35 public import soup.c.types; 36 37 38 /** 39 * A #SoupMessage request or response body. 40 * 41 * Note that while @length always reflects the full length of the 42 * message body, @data is normally %NULL, and will only be filled in 43 * after soup_message_body_flatten() is called. For client-side 44 * messages, this automatically happens for the response body after it 45 * has been fully read, unless you set the 46 * %SOUP_MESSAGE_OVERWRITE_CHUNKS flags. Likewise, for server-side 47 * messages, the request body is automatically filled in after being 48 * read. 49 * 50 * As an added bonus, when @data is filled in, it is always terminated 51 * with a '\0' byte (which is not reflected in @length). 52 */ 53 public final class MessageBody 54 { 55 /** the main Gtk struct */ 56 protected SoupMessageBody* soupMessageBody; 57 protected bool ownedRef; 58 59 /** Get the main Gtk struct */ 60 public SoupMessageBody* getMessageBodyStruct(bool transferOwnership = false) 61 { 62 if (transferOwnership) 63 ownedRef = false; 64 return soupMessageBody; 65 } 66 67 /** the main Gtk struct as a void* */ 68 protected void* getStruct() 69 { 70 return cast(void*)soupMessageBody; 71 } 72 73 /** 74 * Sets our main struct and passes it to the parent class. 75 */ 76 public this (SoupMessageBody* soupMessageBody, bool ownedRef = false) 77 { 78 this.soupMessageBody = soupMessageBody; 79 this.ownedRef = ownedRef; 80 } 81 82 ~this () 83 { 84 if ( Linker.isLoaded(LIBRARY_SOUP[0]) && ownedRef ) 85 soup_message_body_free(soupMessageBody); 86 } 87 88 89 /** 90 * the data 91 */ 92 public @property string data() 93 { 94 return Str.toString(soupMessageBody.data); 95 } 96 97 /** Ditto */ 98 public @property void data(string value) 99 { 100 soupMessageBody.data = Str.toStringz(value); 101 } 102 103 /** 104 * length of @data 105 */ 106 public @property long length() 107 { 108 return soupMessageBody.length; 109 } 110 111 /** Ditto */ 112 public @property void length(long value) 113 { 114 soupMessageBody.length = value; 115 } 116 117 /** */ 118 public static GType getType() 119 { 120 return soup_message_body_get_type(); 121 } 122 123 /** 124 * Creates a new #SoupMessageBody. #SoupMessage uses this internally; you 125 * will not normally need to call it yourself. 126 * 127 * Returns: a new #SoupMessageBody. 128 * 129 * Throws: ConstructionException GTK+ fails to create the object. 130 */ 131 public this() 132 { 133 auto __p = soup_message_body_new(); 134 135 if(__p is null) 136 { 137 throw new ConstructionException("null returned by new"); 138 } 139 140 this(cast(SoupMessageBody*) __p); 141 } 142 143 /** 144 * Appends @length bytes from @data to @body according to @use. 145 * 146 * Params: 147 * use = how to use @data 148 * data = data to append 149 */ 150 public void append(SoupMemoryUse use, ubyte[] data) 151 { 152 soup_message_body_append(soupMessageBody, use, data.ptr, cast(size_t)data.length); 153 } 154 155 /** 156 * Appends the data from @buffer to @body. (#SoupMessageBody uses 157 * #SoupBuffers internally, so this is normally a constant-time 158 * operation that doesn't actually require copying the data in 159 * @buffer.) 160 * 161 * Params: 162 * buffer = a #SoupBuffer 163 */ 164 public void appendBuffer(Buffer buffer) 165 { 166 soup_message_body_append_buffer(soupMessageBody, (buffer is null) ? null : buffer.getBufferStruct()); 167 } 168 169 /** 170 * Appends @length bytes from @data to @body. 171 * 172 * This function is exactly equivalent to soup_message_body_append() 173 * with %SOUP_MEMORY_TAKE as second argument; it exists mainly for 174 * convenience and simplifying language bindings. 175 * 176 * Params: 177 * data = data to append 178 * 179 * Since: 2.32 180 */ 181 public void appendTake(char[] data) 182 { 183 soup_message_body_append_take(soupMessageBody, data.ptr, cast(size_t)data.length); 184 } 185 186 /** 187 * Tags @body as being complete; Call this when using chunked encoding 188 * after you have appended the last chunk. 189 */ 190 public void complete() 191 { 192 soup_message_body_complete(soupMessageBody); 193 } 194 195 /** 196 * Fills in @body's data field with a buffer containing all of the 197 * data in @body (plus an additional '\0' byte not counted by @body's 198 * length field). 199 * 200 * Returns: a #SoupBuffer containing the same data as @body. 201 * (You must free this buffer if you do not want it.) 202 */ 203 public Buffer flatten() 204 { 205 auto __p = soup_message_body_flatten(soupMessageBody); 206 207 if(__p is null) 208 { 209 return null; 210 } 211 212 return ObjectG.getDObject!(Buffer)(cast(SoupBuffer*) __p, true); 213 } 214 215 /** 216 * Frees @body. You will not normally need to use this, as 217 * #SoupMessage frees its associated message bodies automatically. 218 */ 219 public void free() 220 { 221 soup_message_body_free(soupMessageBody); 222 ownedRef = false; 223 } 224 225 /** 226 * Gets the accumulate flag on @body; see 227 * soup_message_body_set_accumulate() for details. 228 * 229 * Returns: the accumulate flag for @body. 230 * 231 * Since: 2.24 232 */ 233 public bool getAccumulate() 234 { 235 return soup_message_body_get_accumulate(soupMessageBody) != 0; 236 } 237 238 /** 239 * Gets a #SoupBuffer containing data from @body starting at @offset. 240 * The size of the returned chunk is unspecified. You can iterate 241 * through the entire body by first calling 242 * soup_message_body_get_chunk() with an offset of 0, and then on each 243 * successive call, increment the offset by the length of the 244 * previously-returned chunk. 245 * 246 * If @offset is greater than or equal to the total length of @body, 247 * then the return value depends on whether or not 248 * soup_message_body_complete() has been called or not; if it has, 249 * then soup_message_body_get_chunk() will return a 0-length chunk 250 * (indicating the end of @body). If it has not, then 251 * soup_message_body_get_chunk() will return %NULL (indicating that 252 * @body may still potentially have more data, but that data is not 253 * currently available). 254 * 255 * Params: 256 * offset = an offset 257 * 258 * Returns: a #SoupBuffer, or %NULL. 259 */ 260 public Buffer getChunk(long offset) 261 { 262 auto __p = soup_message_body_get_chunk(soupMessageBody, offset); 263 264 if(__p is null) 265 { 266 return null; 267 } 268 269 return ObjectG.getDObject!(Buffer)(cast(SoupBuffer*) __p, true); 270 } 271 272 /** 273 * Handles the #SoupMessageBody part of receiving a chunk of data from 274 * the network. Normally this means appending @chunk to @body, exactly 275 * as with soup_message_body_append_buffer(), but if you have set 276 * @body's accumulate flag to %FALSE, then that will not happen. 277 * 278 * This is a low-level method which you should not normally need to 279 * use. 280 * 281 * Params: 282 * chunk = a #SoupBuffer received from the network 283 * 284 * Since: 2.24 285 */ 286 public void gotChunk(Buffer chunk) 287 { 288 soup_message_body_got_chunk(soupMessageBody, (chunk is null) ? null : chunk.getBufferStruct()); 289 } 290 291 /** 292 * Sets or clears the accumulate flag on @body. (The default value is 293 * %TRUE.) If set to %FALSE, @body's %data field will not be filled in 294 * after the body is fully sent/received, and the chunks that make up 295 * @body may be discarded when they are no longer needed. 296 * 297 * In particular, if you set this flag to %FALSE on an "incoming" 298 * message body (that is, the #SoupMessage:response_body of a 299 * client-side message, or #SoupMessage:request_body of a server-side 300 * message), this will cause each chunk of the body to be discarded 301 * after its corresponding #SoupMessage::got_chunk signal is emitted. 302 * (This is equivalent to setting the deprecated 303 * %SOUP_MESSAGE_OVERWRITE_CHUNKS flag on the message.) 304 * 305 * If you set this flag to %FALSE on the #SoupMessage:response_body of 306 * a server-side message, it will cause each chunk of the body to be 307 * discarded after its corresponding #SoupMessage::wrote_chunk signal 308 * is emitted. 309 * 310 * If you set the flag to %FALSE on the #SoupMessage:request_body of a 311 * client-side message, it will block the accumulation of chunks into 312 * @body's %data field, but it will not normally cause the chunks to 313 * be discarded after being written like in the server-side 314 * #SoupMessage:response_body case, because the request body needs to 315 * be kept around in case the request needs to be sent a second time 316 * due to redirection or authentication. However, if you set the 317 * %SOUP_MESSAGE_CAN_REBUILD flag on the message, then the chunks will 318 * be discarded, and you will be responsible for recreating the 319 * request body after the #SoupMessage::restarted signal is emitted. 320 * 321 * Params: 322 * accumulate = whether or not to accumulate body chunks in @body 323 * 324 * Since: 2.24 325 */ 326 public void setAccumulate(bool accumulate) 327 { 328 soup_message_body_set_accumulate(soupMessageBody, accumulate); 329 } 330 331 /** 332 * Deletes all of the data in @body. 333 */ 334 public void truncate() 335 { 336 soup_message_body_truncate(soupMessageBody); 337 } 338 339 /** 340 * Handles the #SoupMessageBody part of writing a chunk of data to the 341 * network. Normally this is a no-op, but if you have set @body's 342 * accumulate flag to %FALSE, then this will cause @chunk to be 343 * discarded to free up memory. 344 * 345 * This is a low-level method which you should not need to use, and 346 * there are further restrictions on its proper use which are not 347 * documented here. 348 * 349 * Params: 350 * chunk = a #SoupBuffer returned from soup_message_body_get_chunk() 351 * 352 * Since: 2.24 353 */ 354 public void wroteChunk(Buffer chunk) 355 { 356 soup_message_body_wrote_chunk(soupMessageBody, (chunk is null) ? null : chunk.getBufferStruct()); 357 } 358 }